package com.iknow.util;

import android.text.TextUtils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil
{
  public static SimpleDateFormat sdf;
  public static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  public static SimpleDateFormat simpleDateFormatTime = new SimpleDateFormat("HH:mm");
  public static final String tag = "com.iknow.util.StringUtil";
  public static SimpleDateFormat timeStrDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

  static
  {
    sdf = new SimpleDateFormat("yyyy-MM-dd");
  }

  public static String DateToStr(Date paramDate)
  {
    String str;
    if (paramDate == null)
      str = null;
    while (true)
    {
      return str;
      str = simpleDateFormat.format(paramDate);
    }
  }

  public static Date StrToDate(String paramString)
  {
    Object localObject;
    if (isEmpty(paramString))
    {
      localObject = null;
      return localObject;
    }
    try
    {
      Date localDate = simpleDateFormat.parse(paramString);
      localObject = localDate;
    }
    catch (ParseException localParseException)
    {
      throw new RuntimeException(localParseException);
    }
  }

  public static boolean compareTime(Date paramDate)
  {
    Calendar localCalendar = Calendar.getInstance();
    try
    {
      localCalendar.setTime(sdf.parse(DateToStr(new Date())));
      label24: Date localDate1 = localCalendar.getTime();
      localCalendar.add(5, 1);
      Date localDate2 = localCalendar.getTime();
      if ((paramDate.after(localDate1)) && (paramDate.before(localDate2)))
      {
        i = 1;
        return i;
      }
      int i = 0;
    }
    catch (ParseException localParseException)
    {
      break label24:
    }
  }

  public static boolean equalsObject(Object paramObject1, Object paramObject2)
  {
    boolean bool;
    if ((paramObject1 == null) && (paramObject2 == null))
      bool = true;
    while (true)
    {
      while (true)
      {
        return bool;
        if ((paramObject1 != null) && (paramObject2 != null))
          break;
        bool = false;
      }
      bool = paramObject1.equals(paramObject2);
    }
  }

  public static boolean equalsString(Object paramObject1, Object paramObject2)
  {
    boolean bool;
    if ((paramObject1 == null) && (paramObject2 == null))
      bool = true;
    while (true)
    {
      while (true)
      {
        return bool;
        if ((paramObject1 != null) && (paramObject2 != null))
          break;
        bool = false;
      }
      bool = paramObject1.toString().trim().toLowerCase().equals(paramObject2.toString().trim().toLowerCase());
    }
  }

  public static String formatHtml(String paramString)
  {
    String str;
    if (isEmpty(paramString))
      str = paramString;
    while (true)
    {
      return str;
      str = paramString.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;").replace("'", "&apos;");
    }
  }

  public static String formatHtmlToText(String paramString)
  {
    String str;
    if (isEmpty(paramString))
      str = paramString;
    while (true)
    {
      return str;
      str = paramString.replace("&amp;", "&").replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"").replace("&apos;", "'").replace("&#39;", "'");
    }
  }

  public static String formatJsonString(String paramString)
  {
    StringBuilder localStringBuilder;
    int i;
    String str;
    if (isEmpty(paramString))
      str = paramString;
    while (true)
    {
      return str;
      localStringBuilder = new StringBuilder();
      i = 0;
      if (i < paramString.length())
        break;
      str = localStringBuilder.toString();
    }
    char c = paramString.charAt(i);
    switch (c)
    {
    default:
      localStringBuilder.append(c);
    case '"':
    case '\\':
    case '/':
    case '\b':
    case '\f':
    case '\n':
    case '\r':
    case '\t':
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    while (true)
                      ++i;
                    localStringBuilder.append("\\\"");
                  }
                  localStringBuilder.append("\\\\");
                }
                localStringBuilder.append("\\/");
              }
              localStringBuilder.append("\\b");
            }
            localStringBuilder.append("\\f");
          }
          localStringBuilder.append("\\n");
        }
        localStringBuilder.append("\\r");
      }
      localStringBuilder.append("\\t");
    }
  }

  public static String formatPostString(String paramString)
  {
    if (isEmpty(paramString));
    while (true)
    {
      return paramString;
      paramString = paramString.replace(";", "^^");
    }
  }

  public static String formatStringToXML(String paramString)
  {
    String str;
    if (isEmpty(paramString))
      str = paramString;
    while (true)
    {
      return str;
      str = paramString.replace("&", "&amp;").replace("'", "&apos;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;");
    }
  }

  public static String formatTellPhoneNumber(String paramString)
  {
    Object localObject;
    if (isEmpty(paramString))
      localObject = null;
    while (true)
    {
      String str2;
      while (true)
      {
        while (true)
        {
          return localObject;
          String str1 = Regex.concatGroups(Regex.NUMBER_PATTERN.matcher(paramString));
          str2 = Regex.concatGroups(Regex.TELLPHONE_PATTERN.matcher(str1));
          if (!(isEmpty(str2)))
            break;
          localObject = null;
        }
        if (!(str2.substring(0, 1).equals("0")))
          break;
        localObject = str2.substring(1, str2.length());
      }
      localObject = str2;
    }
  }

  public static String formatXMLToString(String paramString)
  {
    String str;
    if (isEmpty(paramString))
      str = paramString;
    while (true)
    {
      return str;
      str = paramString.replace("&apos;", "'").replace("&amp;", "&").replace("&quot;", "\"").replace("&lt;", "<").replace("&gt;", ">");
    }
  }

  public static String getBASE64(String paramString)
  {
    String str;
    if (paramString == null)
      str = null;
    while (true)
    {
      return str;
      str = IKBase64.encode(paramString.getBytes());
    }
  }

  public static String getFromBASE64(String paramString)
  {
    String str;
    if (paramString == null)
      str = null;
    while (true)
    {
      return str;
      str = new String(IKBase64.decode(paramString));
    }
  }

  public static String getMD5String(String paramString)
  {
    MessageDigest localMessageDigest;
    try
    {
      localMessageDigest = MessageDigest.getInstance("MD5");
      localMessageDigest.update(paramString.getBytes());
      StringBuilder localStringBuilder = new StringBuilder();
      byte[] arrayOfByte = localMessageDigest.digest();
      int i = arrayOfByte.length;
      int j = 0;
      if (j >= i)
        return localStringBuilder.toString();
      int k = arrayOfByte[j];
      localStringBuilder.append(Integer.toHexString(0xF & k >> 4));
      localStringBuilder.append(Integer.toHexString(k & 0xF));
      ++j;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new RuntimeException("No MD5 algorithm.");
    }
  }

  public static int getStringLength(String paramString)
  {
    int k;
    if (TextUtils.isEmpty(paramString))
      k = 0;
    while (true)
    {
      return k;
      int i = paramString.getBytes().length - paramString.length();
      int j = paramString.length() - paramString.replaceAll("[a-zA-Z]+ ", " ").length();
      k = i + (j + paramString.length() - i - j) / 2;
    }
  }

  public static String getTimeString()
  {
    return timeStrDateFormat.format(new Date());
  }

  // ERROR //
  public static String getValueStringByIKFile(java.io.File paramFile)
  {
    // Byte code:
    //   0: aload_0
    //   1: ifnull +10 -> 11
    //   4: aload_0
    //   5: invokevirtual 279	java/io/File:exists	()Z
    //   8: ifne +7 -> 15
    //   11: aconst_null
    //   12: astore_1
    //   13: aload_1
    //   14: areturn
    //   15: aload_0
    //   16: invokevirtual 282	java/io/File:length	()J
    //   19: lstore_2
    //   20: lload_2
    //   21: lconst_0
    //   22: lcmp
    //   23: ifne +8 -> 31
    //   26: aconst_null
    //   27: astore_1
    //   28: goto -15 -> 13
    //   31: aconst_null
    //   32: checkcast 284	[B
    //   35: pop
    //   36: lload_2
    //   37: ldc2_w 285
    //   40: lcmp
    //   41: iflt +94 -> 135
    //   44: ldc_w 287
    //   47: newarray byte
    //   49: astore 5
    //   51: aconst_null
    //   52: astore 6
    //   54: aconst_null
    //   55: astore 7
    //   57: aconst_null
    //   58: astore 8
    //   60: new 289	java/io/FileInputStream
    //   63: dup
    //   64: aload_0
    //   65: invokespecial 292	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   68: astore 9
    //   70: new 294	java/io/ByteArrayOutputStream
    //   73: dup
    //   74: invokespecial 295	java/io/ByteArrayOutputStream:<init>	()V
    //   77: astore 10
    //   79: aload 9
    //   81: aload 5
    //   83: invokevirtual 301	java/io/InputStream:read	([B)I
    //   86: pop
    //   87: aload 10
    //   89: aload 5
    //   91: invokevirtual 304	java/io/ByteArrayOutputStream:write	([B)V
    //   94: new 104	java/lang/String
    //   97: dup
    //   98: aload 5
    //   100: invokespecial 228	java/lang/String:<init>	([B)V
    //   103: astore 19
    //   105: aload 9
    //   107: ifnull +8 -> 115
    //   110: aload 9
    //   112: invokevirtual 307	java/io/InputStream:close	()V
    //   115: aload 10
    //   117: ifnull +196 -> 313
    //   120: aload 10
    //   122: invokevirtual 308	java/io/ByteArrayOutputStream:close	()V
    //   125: aload 19
    //   127: astore 6
    //   129: aload 6
    //   131: astore_1
    //   132: goto -119 -> 13
    //   135: lload_2
    //   136: l2i
    //   137: newarray byte
    //   139: astore 5
    //   141: goto -90 -> 51
    //   144: astore 23
    //   146: aload 23
    //   148: astore 12
    //   150: new 143	java/lang/StringBuilder
    //   153: dup
    //   154: ldc_w 310
    //   157: invokespecial 311	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   160: aload_0
    //   161: invokevirtual 314	java/io/File:getPath	()Ljava/lang/String;
    //   164: invokevirtual 162	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   167: invokevirtual 149	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   170: aload 12
    //   172: invokestatic 318	com/iknow/util/StringUtil:objToString	(Ljava/lang/Object;)Ljava/lang/String;
    //   175: invokestatic 324	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   178: aload 7
    //   180: ifnull +8 -> 188
    //   183: aload 7
    //   185: invokevirtual 307	java/io/InputStream:close	()V
    //   188: aload 8
    //   190: ifnull -61 -> 129
    //   193: aload 8
    //   195: invokevirtual 308	java/io/ByteArrayOutputStream:close	()V
    //   198: goto -69 -> 129
    //   201: astore 16
    //   203: ldc 12
    //   205: aload 16
    //   207: invokestatic 318	com/iknow/util/StringUtil:objToString	(Ljava/lang/Object;)Ljava/lang/String;
    //   210: invokestatic 324	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   213: goto -84 -> 129
    //   216: astore 17
    //   218: ldc 12
    //   220: aload 17
    //   222: invokestatic 318	com/iknow/util/StringUtil:objToString	(Ljava/lang/Object;)Ljava/lang/String;
    //   225: invokestatic 324	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   228: goto -40 -> 188
    //   231: astore 13
    //   233: aload 7
    //   235: ifnull +8 -> 243
    //   238: aload 7
    //   240: invokevirtual 307	java/io/InputStream:close	()V
    //   243: aload 8
    //   245: ifnull +8 -> 253
    //   248: aload 8
    //   250: invokevirtual 308	java/io/ByteArrayOutputStream:close	()V
    //   253: aload 13
    //   255: athrow
    //   256: astore 15
    //   258: ldc 12
    //   260: aload 15
    //   262: invokestatic 318	com/iknow/util/StringUtil:objToString	(Ljava/lang/Object;)Ljava/lang/String;
    //   265: invokestatic 324	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   268: goto -25 -> 243
    //   271: astore 14
    //   273: ldc 12
    //   275: aload 14
    //   277: invokestatic 318	com/iknow/util/StringUtil:objToString	(Ljava/lang/Object;)Ljava/lang/String;
    //   280: invokestatic 324	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   283: goto -30 -> 253
    //   286: astore 21
    //   288: ldc 12
    //   290: aload 21
    //   292: invokestatic 318	com/iknow/util/StringUtil:objToString	(Ljava/lang/Object;)Ljava/lang/String;
    //   295: invokestatic 324	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   298: goto -183 -> 115
    //   301: astore 20
    //   303: ldc 12
    //   305: aload 20
    //   307: invokestatic 318	com/iknow/util/StringUtil:objToString	(Ljava/lang/Object;)Ljava/lang/String;
    //   310: invokestatic 324	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   313: aload 19
    //   315: astore 6
    //   317: goto -188 -> 129
    //   320: astore 13
    //   322: aload 9
    //   324: astore 7
    //   326: goto -93 -> 233
    //   329: astore 13
    //   331: aload 10
    //   333: astore 8
    //   335: aload 9
    //   337: astore 7
    //   339: goto -106 -> 233
    //   342: astore 22
    //   344: aload 22
    //   346: astore 12
    //   348: aload 9
    //   350: astore 7
    //   352: goto -202 -> 150
    //   355: astore 11
    //   357: aload 11
    //   359: astore 12
    //   361: aload 10
    //   363: astore 8
    //   365: aload 9
    //   367: astore 7
    //   369: goto -219 -> 150
    //
    // Exception table:
    //   from	to	target	type
    //   60	70	144	java/io/IOException
    //   193	198	201	java/io/IOException
    //   183	188	216	java/io/IOException
    //   60	70	231	finally
    //   150	178	231	finally
    //   238	243	256	java/io/IOException
    //   248	253	271	java/io/IOException
    //   110	115	286	java/io/IOException
    //   120	125	301	java/io/IOException
    //   70	79	320	finally
    //   79	105	329	finally
    //   70	79	342	java/io/IOException
    //   79	105	355	java/io/IOException
  }

  public static boolean isChineseCode(char paramChar)
  {
    int i;
    if ((paramChar >= 19968) && (paramChar <= 40869))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public static boolean isEmpty(String paramString)
  {
    int i;
    if ((paramString == null) || (paramString.trim().length() == 0))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public static boolean isNumeric(String paramString)
  {
    int i;
    if (isEmpty(paramString))
      i = 0;
    while (true)
    {
      while (true)
      {
        return i;
        if (Regex.IS_NUMBER_PATTERN.matcher(paramString).matches())
          break;
        i = 0;
      }
      i = 1;
    }
  }

  public static String longToDate(long paramLong)
  {
    Date localDate = new Date(paramLong);
    return simpleDateFormat.format(localDate);
  }

  public static String netParmToString(Map<String, String> paramMap)
  {
    String str1;
    if ((paramMap == null) || (paramMap.size() == 0))
    {
      str1 = "";
      return str1;
    }
    StringBuffer localStringBuffer = new StringBuffer();
    Iterator localIterator = paramMap.keySet().iterator();
    while (true)
    {
      while (!(localIterator.hasNext()))
        str1 = removeEndComma(localStringBuffer.toString(), "&");
      String str2 = (String)localIterator.next();
      localStringBuffer.append(str2);
      localStringBuffer.append("=");
      localStringBuffer.append((String)paramMap.get(str2));
      localStringBuffer.append("&");
    }
  }

  public static String objToString(Object paramObject)
  {
    String str;
    if (paramObject == null)
      str = "";
    while (true)
    {
      while (true)
      {
        while (true)
        {
          return str;
          if (!(paramObject instanceof Timestamp))
            break;
          Timestamp localTimestamp = (Timestamp)paramObject;
          str = simpleDateFormat.format(new Date(localTimestamp.getTime()));
        }
        if (!(paramObject instanceof Date))
          break;
        str = simpleDateFormat.format(paramObject);
      }
      str = paramObject.toString();
    }
  }

  public static String removeEndComma(String paramString1, String paramString2)
  {
    String str;
    if (isEmpty(paramString1))
      str = null;
    while (true)
    {
      while (true)
      {
        int i;
        int j;
        while (true)
        {
          return str;
          i = paramString1.length();
          j = paramString2.length();
          if (!(paramString1.equals(paramString2)))
            break;
          str = "";
        }
        if (!(paramString1.substring(i - j, i).equals(paramString2)))
          break;
        str = paramString1.substring(0, i - j);
      }
      str = paramString1;
    }
  }

  public static String replaceFromUrl(String paramString)
  {
    String str;
    if (isEmpty(paramString))
      str = paramString;
    while (true)
    {
      return str;
      str = paramString.replaceAll("%3D", "=");
    }
  }

  public static double toDouble(String paramString, double paramDouble)
  {
    double d2;
    double d1 = paramDouble;
    try
    {
      if (isEmpty(paramString))
      {
        d2 = d1;
      }
      else
      {
        double d3 = Double.parseDouble(paramString);
        d1 = d3;
        label24: d2 = d1;
      }
    }
    catch (Exception localException)
    {
      break label24:
    }
    return d2;
  }

  public static float toFloat(String paramString, float paramFloat)
  {
    float f2;
    float f1 = paramFloat;
    try
    {
      if (isEmpty(paramString))
      {
        f2 = f1;
      }
      else
      {
        float f3 = Float.parseFloat(paramString);
        f1 = f3;
        label24: f2 = f1;
      }
    }
    catch (Exception localException)
    {
      break label24:
    }
    return f2;
  }

  public static int toInteger(String paramString, int paramInt)
  {
    int i;
    if (isNumeric(paramString))
      i = Integer.parseInt(paramString);
    while (true)
    {
      return i;
      i = paramInt;
    }
  }

  public static int[] toIntegerArray(String[] paramArrayOfString, int paramInt)
  {
    Object localObject;
    if (paramArrayOfString == null)
    {
      localObject = new int[0];
      return localObject;
    }
    int[] arrayOfInt = new int[paramArrayOfString.length];
    int i = 0;
    while (true)
    {
      while (i >= paramArrayOfString.length)
        localObject = arrayOfInt;
      arrayOfInt[i] = toInteger(paramArrayOfString[i], paramInt);
      ++i;
    }
  }

  public static long toLong(String paramString, long paramLong)
  {
    long l2;
    long l1 = paramLong;
    try
    {
      if (isEmpty(paramString))
      {
        l2 = l1;
      }
      else
      {
        long l3 = Long.parseLong(paramString);
        l1 = l3;
        label24: l2 = l1;
      }
    }
    catch (Exception localException)
    {
      break label24:
    }
    return l2;
  }

  public static String toSessionEncoded(String paramString)
  {
    if ((paramString != null) && (0 != 0))
      paramString.indexOf("jsessionid");
    return paramString;
  }

  public static String toUtf8String(String paramString)
  {
    return paramString;
  }
}